<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
	include 'project_panel.tpl.php';
?>
	<div class="row">
		<div class="col-lg-12">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="icon-list"></i> Nhóm dự án</div>
				</div>
				<div class="panel-body">
					<form action="javascript:groupProject();" class="form-horizontal" id="group_project">
						<input type='hidden' name='mod' value='group_project' />
						<div class="form-group">
							<div class="col-lg-6">
								<input type="text" id="search_parent" class="form-control" placeholder="Mã hợp đồng / Tên dự án (Cha)" />
								<select name="parent" class="form-control" size="7" id="parent">
									<?php foreach($this->projects as $project):?>
									<option value="<?php echo $project['pId'];?>"><?php echo $project['pName'];?></option>
									<?php endforeach;?>
								</select>
							</div>
							<div class="col-lg-6">
								<input type="text" class="form-control" id="search_child" placeholder="Mã hợp đồng / Tên dự án (Con)" />
								<select name="child[]" class="form-control" multiple="multiple" size="7" id="child">
									<?php foreach($this->projects as $project):?>
									<option value="<?php echo $project['pId'];?>"><?php echo $project['pName'];?></option>
									<?php endforeach;?>
								</select>
							</div>
						</div>
						<div class="form-group">
							<div class="col-lg-12 text-center">
								<button type="submit" class="btn btn-primary"><i class="icon-ok"></i> <?php echo $this->language['accept'];?></button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</div>
	<script>
	$(function() {
		var timeout;

		$("#search_parent").keyup(function(){
			var k = $(this).val();
			if(k.length >= 3){
				clearTimeout(timeout);
				timeout = setTimeout(function(){
					$.ajax({
						type: 'POST',
						url: '?func=project_ajax',
						data: {
							mod: 'search_project',
							keyword: k
						},
						dataType: 'json',
						success: function(msg){
							if(msg.result == true){
								var j = msg.projects;
								var options = '';
								for(var i = 0; i < j.length ; i++){
									options += '<option value="' + j[i].pId + '">' + j[i].pName + '</option>';
								}
								$('#parent').html(options);
							}
						}
					});
				},1000);
			}
		});
		$("#search_child").keyup(function(){
			var k = $(this).val();
			if(k.length >= 3){
				clearTimeout(timeout);
				timeout = setTimeout(function(){
					$.ajax({
						type: 'POST',
						url: '?func=project_ajax',
						data: {
							mod: 'search_project',
							keyword: k,
							type: 'child'
						},
						dataType: 'json',
						success: function(msg){
							if(msg.result == true){
								var j = msg.projects;
								var options = '';
								for(var i = 0; i < j.length ; i++){
									options += '<option value="' + j[i].pId + '">' + j[i].pName + '</option>';
								}
								$('#child').html(options);
							}
						}
					});
				},1000);
			}
		});
	});
	</script>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>